package com.nanuminc.market.today;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.view.View;

import com.nanuminc.market.NMConstants;
import com.nanuminc.market.R;
import com.nanuminc.market.common.AbstractPagerAdapter;
import com.nanuminc.market.common.NavigationGroupActivity;
import com.nanuminc.market.today.type.TodayListAB;
import com.nanuminc.market.today.type.TodayListC;

public class TodayMain extends NavigationGroupActivity {
	public final static int VIEW_PAGE_NUM = NMConstants.VIEW_PAGE_NUM;
	int nowPage = 0;
    
	ViewPager vp_main = null;	//ViewPager
    CustomPagerAdapter cpa = null;
    Context context = null;
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
	    super.onCreate(savedInstanceState);
	    setContentView(R.layout.todaymain);
	    context = this;
	    
	    cpa = new CustomPagerAdapter();
	    vp_main = (ViewPager) findViewById(R.id.vp_main); //View Pager를 setAdapter를 통해 PagerAdapter와 연결
        vp_main.setAdapter(cpa);
        
        vp_main.setOnPageChangeListener(new OnPageChangeListener(){

			@Override
			public void onPageScrollStateChanged(int state) {}

			@Override
			public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {}

			@Override
			public void onPageSelected(int position) {
				pageCheck(position);				
			}
        	
        });
	}

	public void pageCheck(int pageNum){
		nowPage = pageNum;
    }

	class CustomPagerAdapter extends AbstractPagerAdapter {

		@Override
		public int getCount() {
	        return VIEW_PAGE_NUM;
		}

		@Override
		public Object instantiateItem(View collection, int position) {
	    	View view = null;
	    	Intent intent = null;

	    	if(position == 0) {
	    		intent = new Intent(TodayMain.this, TodayListAB.class);
				intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |Intent.FLAG_ACTIVITY_SINGLE_TOP);
	    	} else if(position == 1) {
	    		intent = new Intent(TodayMain.this, TodayListC.class);
				intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |Intent.FLAG_ACTIVITY_SINGLE_TOP);
	    	}
	    	view = getLocalActivityManager().startActivity("MainActivity",intent).getDecorView();
	        ((ViewPager) collection).addView(view,position);
		return view;
		}
	}
}

